<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/tongyong.css">
    <link rel="stylesheet" href="../css/denglu.css">
</head>

<body>
    <h1>请你登录账号 开启小店</h1>
    <div class="jumbotron">
        <div class="login">
            <form class="form-horizontal">
                <div class="form-group">
                    <div class="mop">
                        <label for="username" class="col-sm-2 control-label">用户名:</label>
                    </div>
                    <div class="col-sm-10">
                        <input name="name" type="text" class="form-control" id="username" placeholder="用户名">
                    </div>
                </div>
                <div class="form-group">
                    <div class="mop">
                        <label for="password" class="col-sm-2 control-label">密码:</label>
                    </div>

                    <div class="col-sm-10">
                        <input name="pwd" type="password" class="form-control" id="password" placeholder="密码">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10 ooo">
                        <button type="button" class="btn btn-default">登录</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/myAjax.js"></script>
    <script src="../js/tools.js"></script>
    <script src="../js/cookie.js"></script>
    <script>
        $('button').click(function() {
            //发送的ajax请求方式是post，携带参数userName，userPwd
            const xhr = myPromiseJQueryAjax('../server/goods_login.php', 'post', {
                userName: $('[name="name"]').val(),
                userPwd: $('[name="pwd"]').val()
            }, 'json');
            xhr.then(function(res) {
                console.log(res)
                    //根据结果动态生成页面
                if (res.result === 1) {
                    //登录成功
                    //的核定cookie信息
                    //0表示没有登录，1表示登录
                    //其他页面可以通过cookie的login数据判断，是否已经登录
                    mySetCookie('login', 1, 7 * 24 * 60 * 60, '/');
                    //跳转页面
                    if (window.confirm('你登录成功，点击确定跳转页面')) {
                        window.location.href = `${window.location.search.substr(5)}`;
                    }
                } else if (res.result === 0) {
                    //登录是失败
                    window.alert('你的账号密码有误，请重新登录');
                }
            })
        });
    </script>
</body>

</html>